<?php

namespace App\Admin\Controllers;

use App\AdvertList;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class AdvertListController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '广告管理';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new AdvertList);
        $grid->actions(function ($actions) {
            // 去掉查看
            $actions->disableView();
            $actions->disableEdit();
        });
        $grid->model()->orderBy('id','desc');
        $grid->column('id', 'id');
        $grid->column('video_type','广告类型')->select(['banner广告',  '视频广告']);
        $path_type_name = ['首页','详情页底部','详情页推荐','签约作者专栏', '个人中心'];
        $grid->column('path_type', '广告位置')->display(function($path_type) use ($path_type_name) {
            return $path_type_name[$path_type];
        });
        $advert_state = [
            'on'  => ['value' => 1, 'text' => '打开', 'color' => 'success'],
            'off' => ['value' => 0, 'text' => '关闭', 'color' => 'danger'],
        ];
        $grid->advert_state('广告开关')->switch($advert_state);
        $grid->column('interval_num','间隔条数')->select([6 => '每隔六个', 8 => '每隔八个', 10 => '每隔十个']);
        $screen_state = [
            'on'  => ['value' => 1, 'text' => '打开', 'color' => 'success'],
            'off' => ['value' => 0, 'text' => '关闭', 'color' => 'danger'],
        ];
        $grid->screen_state('插屏开关')->switch($screen_state);
        $grid->column('created_at', '创建时间');

        $grid->column('updated_at', '更新时间');

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {

    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new AdvertList);
        $video_type = ['banner广告', '视频广告'];
        $form->select('video_type', '广告类型')->options($video_type);
        $path_type = ['首页', '详情页底部', '详情页推荐', '签约作者专栏', '个人中心'];
        $form->select('path_type', '广告位置')->options($path_type);
        $form->switch('advert_state', '广告开关')->default(1);
        $interval_num = [6 => '每隔六个', 8 => '每隔八个', 10 => '每隔十个'];
        $form->select('interval_num', '间隔条数')->options($interval_num);
        $form->switch('screen_state', '插屏开关')->default(1);
        return $form;
    }
}
